"use strict";

document.body.onload = function()
{
    window.sugar = new Sugar("a-ib", 2);
    sugar.isJoin(function(json) {
        alert("已登录", 1000);
        sugar.getNode("h1")[0].innerText = json.nickname;
    }, function() {
        var lgm = sugar.need("infoBox", {
            success: function(json) {
                sugar.getNode("h1")[0].innerText = json.nickname;
                lgm.hide();
            }
        });
    });

    sugar.getNode(".nav-start").forEach(function (val, index, array) {
        val.addEventListener("click", function (event) {
            sugar.isJoin(function(json) {
                if (confirm("是否确认注销")) {
                    sugar.leave(true);
                }
            }, function() {
                var lgm = sugar.need("infoBox", {
                    success: function (json) {
                        console.log(json);
                        sugar.getNode("h1")[0].innerText = json.Token;
                        lgm.hide();
                    }
                });
            });
        });
    });
}